﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using SailHero.Soft.FrameWork.DAO.Core;
using SailHero.Soft.FrameWork.IDomainRepositories.Contracts;
using SailHero.Soft.FrameWork.Models;

namespace SailHero.Soft.FrameWork.DomainRepositories
{
    public class TB_CLIENTSRepository : EFRepository<TB_CLIENTS>, ITB_CLIENTSRepository
    {
        public TB_CLIENTSRepository()
            : base("HJT212DB")
        {
        }
        /// <summary>
        /// 三表左连接，left join Right Join相似
        /// </summary>
        public IEnumerable<Sys_UserRole> GetLeftJoinData()
        {

            var v = from temp1 in base.DbContext.Set<Sys_User>()
                    join temp2 in base.DbContext.Set<Sys_UserInRole>() on temp1.UserID equals temp2.UserID into deval
                    from x in deval.DefaultIfEmpty()
                    join temp3 in DbContext.Set<Sys_Role>() on x.RoleID equals temp3.RoleID into sply
                    from y in sply.DefaultIfEmpty()
                    select new Sys_UserRole()
                    {
                        UserID = temp1.UserID,
                        Account = temp1.Account,
                        UserCName = temp1.UserCName,
                        UserEName = temp1.UserEName,
                        RoleId = y.RoleID,
                        RoleName = y.RoleName
                    };
            return v;
            //return null;
        }
    }
}